//
//  ViewController.m
//  Notification
//
//  Created by Apple on 2017/3/15.
//  Copyright © 2017年 Apple. All rights reserved.
//
#import "ViewController.h"
#import "textVC.h"
#import "homePageCell.h"
#import "switchVC.h"
#import "scrollowVC.h"
#import "webViewVC.h"
#import "alertVC.h"
#import "segmentVC.h"
#import "tableVC.h"
#import "activityVC.h"
#import "dataPickerVC.h"
#import "HongFile.pch"
#import "presentVC.h"
@interface ViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"Demo";
#pragma mark-设置导航栏颜色
//    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
#pragma mark-改变导航栏字体大小和颜色
//    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:20]}];
#pragma mark-添加数组
    self.array = [NSArray arrayWithObjects:@"ScrollowView",@"UIButton",@"Text",@"UIWebView",@"Alert",@"Segment",@"TableView",@"Activity",@"DatePicker", nil];
#pragma mark-添加左边图片
    self.leftIma = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"beautifulGirl.jpg"]];
    self.leftIma.frame = CGRectMake(20, 70, 130, 200);
    self.leftIma.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.leftIma];
#pragma mark-添加右边图片
    self.rightIma = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"doNo.jpg"]];
    self.rightIma.frame = CGRectMake(SCREEN_WIDTH-150, 70, 130, 200);
    self.rightIma.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:self.rightIma];
#pragma mark-添加lab
    self.leftLab = [[UILabel alloc]initWithFrame:CGRectMake(20,290, 130, 30)];
    self.leftLab.backgroundColor = [UIColor whiteColor];
    self.leftLab.text = @"美女";
    self.leftLab.textAlignment = NSTextAlignmentCenter;
    self.leftLab.layer.borderWidth = 1;
    self.leftLab.layer.borderColor = [UIColor grayColor].CGColor;
    self.leftLab.alpha = 0.8;
    [self.view addSubview:self.leftLab];
#pragma mark-添加lab
    self.rightLab = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-150, 290, 130, 30)];
    self.rightLab.backgroundColor = [UIColor whiteColor];
    self.rightLab.text = @"改变";
    self.rightLab.textAlignment = NSTextAlignmentCenter;
    self.rightLab.layer.borderWidth = 1;
    self.rightLab.layer.borderColor = [UIColor grayColor].CGColor;
    self.rightLab.alpha = 0.8;
    [self.view addSubview:self.rightLab];
#pragma mark-改变按钮
    self.switcher = [[UISwitch alloc]initWithFrame:CGRectMake(60, 340, 51, 31)];
    [self.switcher setOn:YES animated:YES];
//    self.switcher.transform = CGAffineTransformMakeScale(0.5, 0.5);
    [self.switcher setTintColor:[UIColor grayColor]];
    [self.switcher setOnTintColor:[UIColor lightGrayColor]];
    [self.switcher addTarget:self action:@selector(changeImage:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:self.switcher];
#pragma mark-添加集合试图
#pragma mark-初始化布局对象
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
#pragma mark-设置每个item的大小
    layout.itemSize = CGSizeMake(80, 40);
#pragma mark-设置每个item之间的最小的间距 行列间距默认是10
    layout.minimumLineSpacing = 10;
    layout.minimumInteritemSpacing = 10;
#pragma mark-设置集合试图距离上下左右的距离
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
#pragma mark-设置滑动方向
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
#pragma mark-初始化集合试图 并添加参数-集合试图的布局
    self.collect = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 400, SCREEN_WIDTH, SCREEN_HEIGHT-400) collectionViewLayout:layout];
    self.collect.delegate = self;
    self.collect.backgroundColor = [UIColor whiteColor];
    self.collect.dataSource = self;
    [self.collect registerClass:[homePageCell class] forCellWithReuseIdentifier:@"duile"];
    [self.view addSubview:self.collect];
    
#pragma mark-设置模态跳转按钮
    UIButton*pButton = [UIButton buttonWithType:UIButtonTypeCustom];
    pButton.frame = CGRectMake(SCREEN_WIDTH-110, 340, 50, 30);
    [pButton setTitle:@"模态" forState:UIControlStateNormal];
    [pButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    pButton.backgroundColor = [UIColor whiteColor];
    pButton.layer.borderWidth = 1;
    pButton.alpha = 0.8;
    pButton.layer.borderColor = [UIColor grayColor].CGColor;
    [self.view addSubview:pButton];
    [pButton addTarget:self action:@selector(MTTurnOver) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void)MTTurnOver{
    presentVC*vc = [[presentVC alloc]init];
    [self presentViewController:vc animated:YES completion:nil];
}
#pragma mark-设置每个section里面有多少个cell
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.array.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    homePageCell*cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"duile" forIndexPath:indexPath];
    cell.lab.text = self.array[indexPath.row];
    cell.lab.layer.borderWidth = 1;
    cell.lab.textAlignment = NSTextAlignmentCenter;
    cell.lab.font = [UIFont systemFontOfSize:12];
    cell.lab.layer.borderColor = [UIColor grayColor].CGColor;
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    UIViewController * vc =[self returnBack:indexPath.row];
    [self.navigationController pushViewController:vc animated:YES];
}
-(UIViewController*)returnBack:(NSInteger)index{
    if (index == 0) {
        scrollowVC*vc = [[scrollowVC alloc]init];
        return vc;
    }else if (index == 1){
        switchVC*vc = [[switchVC alloc]init];
        return vc;
    }else if (index == 2){
        textVC*vc = [[textVC alloc]init];
        return vc;
    }else if (index == 3){
        webViewVC*vc = [[webViewVC alloc]init];
        return vc;
    }else if (index == 4){
        alertVC*vc = [[alertVC alloc]init];
        return vc;
    }else if (index == 5){
        segmentVC*vc = [[segmentVC alloc]init];
        return vc;
    }else if (index == 6){
        tableVC*vc = [[tableVC alloc]init];
        return vc;
    }else if (index == 7){
        activityVC*vc = [[activityVC alloc]init];
        return vc;
    }else if (index == 8){
        dataPickerVC*vc = [[dataPickerVC alloc]init];
        return vc;
    }
    return NULL;
}
//# pragma mark-监听事件
//-(void)setnota:(NSNotification*)sender{
//    NSLog(@"%@",sender.userInfo);
//    self.rightLab.text = sender.object;
//}
-(void)changeImage:(UISwitch*)switcher{
    BOOL isOn = [self.switcher isOn];
    if (isOn) {
        self.leftLab.text = @"美女";
        self.leftIma.image = [UIImage imageNamed:@"beautifulGirl.jpg"];
    }else{
        self.leftLab.text = @"野兽";
        self.leftIma.image = [UIImage imageNamed:@"doNo.jpg"];
    }
}
-(void)buttonClick:(UIButton*)button{
    textVC * te = [[textVC alloc]init];
    [self.navigationController pushViewController:te animated:YES];
//    [self presentViewController:te animated:YES completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
